package com.joker.userExam.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.joker.userExam.dao.mapper.StudentScoreMapper;
import com.joker.userExam.dao.repo.StudentScoreRepo;
import com.joker.userExam.model.StudentScore;
import com.joker.userExam.service.IScoreManage;
import com.joker.userExam.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 李杰
 * @date 2021/5/9 - 19:46
 */
@Service
public class ScoreManageImpl implements IScoreManage {
    @Autowired
    StudentScoreRepo studentScoreRepo;
    @Autowired
    StudentScoreMapper studentScoreMapper;

    @Override
    public ResultUtil queryScoreInfo() {
        return ResultUtil.ok("success", studentScoreRepo.list());
    }

    @Override
    public ResultUtil deleteScoreById(Integer id) {
        boolean res = studentScoreRepo.removeById(id);
        if (res) {
            return ResultUtil.ok("success");
        } else {
            return ResultUtil.error("error");
        }
    }

    @Override
    public ResultUtil queryScoreByCondition(StudentScore studentScore) {
        QueryWrapper<StudentScore> queryWrapper = new QueryWrapper<>();
        Integer typeNo = studentScore.getType();
        if (typeNo != 6 && typeNo != null) {
            queryWrapper.eq("type", typeNo);
        }
        queryWrapper.orderByDesc("create_time");
        List<StudentScore> list = studentScoreRepo.list(queryWrapper);
        return ResultUtil.ok("success", list);
    }

}
